<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Row Editing in DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="./jquery-easyui/demo.css">
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <script type="text/javascript" src="./jquery-easyui/js/jquery.min.js"></script>
    <script type="text/javascript" src="./jquery-easyui/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./js/common/common.js"></script>
    <script type="text/javascript" src="./js/common/url.js"></script>
    <script type="text/javascript" src="./js/common/loader.js"></script>
    <script type="text/javascript" src='./js/common/month.js'></script>
    <script type="text/javascript ">
    var url;
    var edit_id;
    var deptId = localStorage.deptId;

    function doSearch() {
        $('#tt').datagrid('load', {
            statusCode: $('#statusCode').combobox('getValue'),
            type: $('#type').combobox('getValue'),
            helpDate: $('#helpDate').datebox('getValue'),
            deptId: deptId
        });
        $('#tt').datagrid('unselectAll');

    }

    function getExcelUrl(test) {
        console.log(test);
        var statusCode = $('#statusCode').combobox('getValue'),
            type = $('#type').combobox('getValue'),
            helpDate = $('#helpDate').datebox('getValue')
        var url = baseUrl + 'jasper/zgExceldownload.do?helpDate=' + helpDate + "&statusCode=" + statusCode + "&type=" + type + "&deptId=" + deptId;
        // var url = baseUrl + 'jasper/zgExceldownload.do?helpDate=' + helpDate + "&statusCode=" + statusCode + +"&type=" + type + "&deptId=" + deptId;

        $('#url').attr('href', url)
    }

    function withdraw() {
        var statusCode = $('#statusCode').combobox('getValue');
        if (statusCode == 1) {
            var rows = $('#tt').datagrid('getSelections');
            var ids = '';
            $.each(rows, function(i, val) {
                ids = val.id + ',' + ids
            })
            var newUrl = 'http://115.29.136.190:8080/help/usr/buzhu/withdraw.do' + "?buzhuList=" + ids
            $.ajax({
                type: "POST",
                url: newUrl,
                // data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(result) {
                    if (result.status == 1) {
                        $('#dlg').dialog('close'); // close the dialog
                        $('#tt').datagrid('reload'); // reload the user data
                    } else {
                        $.messager.show({ // show error message
                            title: 'Error',
                            msg: result.message
                        });
                    }
                }
            })
        } else {
            alert('只能修改未提交的记录')

        }

    }

    function editBuzhu() {
        var row = $('#tt').datagrid('getSelections');
        var statusCode = $('#statusCode').combobox('getValue');
        if (statusCode == 0) {
            console.log(row);
            if (row.length != 1) {
                alert("只能选择一条数据");
                return false;
            }
            if (row[0]) {
                $('#dlg').dialog('open').dialog('center').dialog('setTitle', '编辑审核信息');
                $('#fm').form('clear');
                $('#fm').form('load', row[0]);
                if (row[0].type == 0) {
                    $("#edit_type").textbox('setValue', "正常发放");
                    url = 'http://115.29.136.190:8080/help/usr/buzhu/updateUnsubmittedBuzhuWithCheck.do'
                } else {
                    $("#edit_type").textbox('setValue', "补助发放");
                    url = 'http://115.29.136.190:8080/help/usr/buzhu/updateUnsubmittedBuzhuWithoutCheck.do'
                }
                edit_id = row[0].id;
                // $('#edit_type').combobox('setValue', '0')

            } else {
                alert('请先选择一条记录')
            }
        } else {
            alert('只能修改未提交的记录')
            return true
        }

    }

    function saveBuzhu() {
        var data = $("#fm").serializeObject();
        data.statusCode = 0;
        data.id = edit_id;
        if ($("#fm").form('validate')) {
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(result) {
                    if (result.status == 1) {
                        $('#dlg').dialog('close'); // close the dialog
                        $('#tt').datagrid('reload'); // reload the user data
                    } else {
                        $.messager.show({ // show error message
                            title: 'Error',
                            msg: result.message
                        });
                    }
                }
            })
        };
    }


    $(function() {
        $('#tt').datagrid({
            title: '补助信息查看',
            iconCls: 'icon-edit',
            width: "100%",
            height: "auto",
            fit: true,
            singleSelect: false,
            idField: 'id',
            url: buzhu_url.queryBuZhu,
            pagination: true,
            pageSize: 5,
            pageList: [5, 10, 15, 20],
            method: 'post',
            queryParams: {
                deptId: deptId,
                statusCode: 2,
                type: 0,
            },
            columns: [
                [{
                    field: 'stuId',
                    title: '学号',
                    align: 'center',
                    width: "15%"
                }, {
                    field: 'studentName',
                    title: '姓名',
                    align: 'center',
                    width: "12%"
                }, {
                    field: 'bankName',
                    title: '银行',
                    width: "7%",
                    align: 'center',
                }, {
                    field: 'bankNo',
                    title: '银行卡号',
                    width: "15%",
                    align: 'center',
                }, {
                    field: 'helpDate',
                    title: '申请年月',
                    align: 'center',
                    width: "12%"
                }, {
                    field: 'money',
                    title: '金额',
                    align: 'center',
                    width: "5%"
                }, {
                    field: 'remark',
                    title: '备注',
                    align: 'center',
                    width: "12%"
                }, {
                    field: 'statusCodeName',
                    title: '状态',
                    width: "12%",
                    align: 'center',
                }]
            ],
            toolbar: '#toolbar'
        });

        $('#cc').combobox({
                url: url_queryDept,
                valueField: 'deptId',
                textField: 'deptName',
                method: 'post',
                multiple: true,
                loader: cloader,
                panelHeight: 200,
            })
            // $('#edit_date').combobox({
            //     url: url_queryDate,
            //     valueField: 'helpDate',
            //     textField: 'helpDate',
            //     method: 'get',
            //     multiple: false,
            //     loader: dateloader,
            //     panelHeight: 'auto',
            //     width: '200'
            // });
        $('#statusCode').combobox('setValue', 2)
        $('#type').combobox('setValue', '0');

    });
    </script>
</head>

<body>
    <!-- <h2>审核信息查看</h2> -->
    <!-- <p></p> -->
    <div id="toolbar">
        <div id="ts" style="padding:3px">
            <span>审核状态:</span>
            <select id="statusCode" value="2" class="easyui-combobox" name="statusCode" style="width:100px;" panelHeight="auto">
                <option value="">全部</option>
                <option value="0">未提交</option>
                <option value="1">已提交待审核</option>
                <option value="2">审核通过</option>
                <option value="3">审核未通过</option>
            </select>
            <span>补助类型:</span>
            <select id="type" value="2" class="easyui-combobox" name="type" panelHeight="auto" style="width:100px;">
                <option value="">全部</option>
                <option value="0">正常发放</option>
                <option value="1">补助发放</option>
            </select>
            <span>年月:</span>
            <input id="helpDate" type="text" class="easyui-datebox" data-options="formatter:myFormatter,parser:myParser">
            <!-- <input name='helpDate' value="" style="line-height:26px;border:1px solid #ccc"> -->
            <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="doSearch(this)">Query</a>
            <!-- <a href="#" class="easyui-linkbutton" plain="true" >Search</a> -->
        </div>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editBuzhu()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="withdraw()">撤回已提交记录</a>
        <a id="url" href="" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="getExcelUrl()"> 下载报表</a>
    </div>
    <table id="tt"></table>
    <!-- 编辑补助对话框 -->
    <div id="dlg" class="easyui-dialog" style="width:500px" closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">审核信息</div>
            <div style="margin-bottom:10px">
                <input id="edit_stuId" name="stuId" class="easyui-textbox" required="true" label="学号:" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_name" name="studentName" class="easyui-textbox" required="true" label="姓名" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_deptId" name="deptId" class="easyui-textbox" label="部门编号:" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_bankName" name="bankName" class="easyui-textbox" label="银行" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_bankNo" name="bankNo" class="easyui-textbox" label="银行卡号" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_type" name="type" class="easyui-textbox" label="类型" disabled="true" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_date" name="helpDate" class="easyui-textbox" label="申请年月" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input id="edit_money" name="money" class="easyui-numberbox" label="申请金额" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveBuzhu()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
</body>

</html>
